﻿using System;

namespace IssueIT.Core.Domain.Model
{
	public class User : IEntity, IAssignable
	{
		public static User Unknown = new UnknownUser();

		private class UnknownUser : User
		{
			public UnknownUser() : base(EmailAddress.None, "Unknown user", Company.Any)
			{
				Id = Guid.Empty;
			}
		}

		public User(string email, string name, Company company) : this(new EmailAddress(email, name), name, company)
		{
		}

		public User(EmailAddress email, string name, Company company)
		{
			Email = email;
			Name = name;
			Company = company;
		}

		public Guid Id { get; protected set; }
		public EmailAddress Email { get; private set; }
		public string Name { get; private set; }
		public Company Company { get; private set; }

		public bool Equals(User other)
		{
			if( ReferenceEquals(null, other) )
			{
				return false;
			}
			if( ReferenceEquals(this, other) )
			{
				return true;
			}
			return other.Id.Equals(Id);
		}

		public override bool Equals(object obj)
		{
			return Equals(obj as User);
		}

		public override int GetHashCode()
		{
			return Id.GetHashCode();
		}
	}
}